Red Hat System Administration II 8.2

Упражнение под руководством преподавателя: Изучение и устранение проблем SELinux

В этой лабораторной работе вы узнаете, как устранять проблемы с отказом в доступе, связанные с SELinux.

Результаты

Вы сможете использовать различные утилиты для устранения проблем SELinux.

Войдите на workstation как пользователь student с паролем student.

На workstation выполните команду lab selinux-issues start. Эта команда запускает подготовительный сценарий, который проверяет доступность машины servera в сети. Сценарий также устанавливает службу httpd, разрешает HTTP-подключения в брандмауэре на servera и удаляет контекст SELinux для каталога /custom.

[student@workstation ~]$ lab selinux-issues start
  1. В веб-браузере на workstation попробуйте открыть http://servera/index.html. Вы увидите сообщение о том, что у вас нет разрешения на доступ к файлу.

  2. С помощью команды ssh войдите на машину servera как пользователь student. Системы настроены на использование ключей SSH для аутентификации, поэтому пароль не требуется.

    [student@workstation ~]$ ssh student@servera
    ...output omitted...
    [student@servera ~]$  
  3. Выполните команду sudo -i, чтобы переключиться на пользователя root. Пароль для пользователя student — student.

    [student@servera ~]$ sudo -i
    [sudo] password for student: student
    [root@servera ~]# 
  4. С помощью команды less отобразите содержимое /var/log/messages. Нажмите клавишу / и выполните поиск sealert. Скопируйте предложенную команду sealert, чтобы использовать ее на следующем шаге. Нажмите клавишу q для выхода из команды less.

    [root@servera ~]# less /var/log/messages
    ...output omitted...
    Mar 28 06:07:03 servera setroubleshoot[15326]: SELinux is preventing /usr/sbin/httpd from getattr access on the file /custom/index.html. For complete SELinux messages run: sealert -l b1c9cc8f-a953-4625-b79b-82c4f4f1fee3
    Mar 28 06:07:03 servera platform-python[15326]: SELinux is preventing /usr/sbin/httpd from getattr access on the file /custom/index.html.#012#012*****  Plugin catchall (100. confidence) suggests   **************************#012#012If you believe that httpd should be allowed getattr access on the index.html file by default.#012Then you should report this as a bug.#012You can generate a local policy module to allow this access.#012Do#012allow this access for now by executing:#012# ausearch -c 'httpd' --raw | audit2allow -M my-httpd#012# semodule -X 300 -i my-httpd.pp#012
    Mar 28 06:07:04 servera setroubleshoot[15326]: failed to retrieve rpm info for /custom/index.html
    ...output omitted...
  5. Выполните предложенную команду sealert. Обратите внимание на исходный контекст, целевые объекты, политику и принудительный режим.

    [root@servera ~]# sealert -l b1c9cc8f-a953-4625-b79b-82c4f4f1fee3
    SELinux is preventing /usr/sbin/httpd from getattr access on the file /custom/index.html.
    
    *****  Plugin catchall (100. confidence) suggests   **************************
    
    If you believe that httpd should be allowed getattr access on the index.html file by default.
    Then you should report this as a bug.
    You can generate a local policy module to allow this access.
    Do
    allow this access for now by executing:
    # ausearch -c 'httpd' --raw | audit2allow -M my-httpd
    # semodule -X 300 -i my-httpd.pp
    
    
    Additional Information:
    Source Context                system_u:system_r:httpd_t:s0
    Target Context                unconfined_u:object_r:default_t:s0
    Target Objects                /custom/index.html [ file ]
    Source                        httpd
    Source Path                   /usr/sbin/httpd
    Port                          <Unknown>
    Host                          servera.lab.example.com
    Source RPM Packages
    Target RPM Packages
    Policy RPM                    selinux-policy-3.14.1-59.el8.noarch
    Selinux Enabled               True
    Policy Type                   targeted
    Enforcing Mode                Enforcing
    Host Name                     servera.lab.example.com
    Platform                      Linux servera.lab.example.com
                                  4.18.0-67.el8.x86_64 #1 SMP Sat Feb 9 12:44:00
                                  UTC 2019 x86_64 x86_64
    Alert Count                   18
    First Seen                    2019-03-25 19:25:28 CET
    Last Seen                     2019-03-28 11:07:00 CET
    Local ID                      b1c9cc8f-a953-4625-b79b-82c4f4f1fee3
    
    Raw Audit Messages
    type=AVC msg=audit(1553767620.970:16958): avc:  denied  { getattr } for  pid=15067 comm="httpd" path="/custom/index.html" dev="vda1" ino=4208311 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file permissive=0
    
    
    Hash: httpd,httpd_t,default_t,file,getattr
  6. Раздел Raw Audit Messages команды sealert содержит информацию из файла /var/log/audit/audit.log. Используйте команду ausearch для выполнения поиска в файле /var/log/audit/audit.log. Опция -m выполняет поиск по типу сообщения. Опция -ts выполняет поиск по времени. Эта запись идентифицирует процесс и файл, вызывающие предупреждение. Процесс — веб-сервер Apache httpd, файл — /custom/index.html, а контекст — system_r:httpd_t.

    [root@servera ~]# ausearch -m AVC -ts recent
    ----
    time->Thu Mar 28 13:39:30 2019
    type=PROCTITLE msg=audit(1553776770.651:17000): proctitle=2F7573722F7362696E2F6874747064002D44464F524547524F554E44
    type=SYSCALL msg=audit(1553776770.651:17000): arch=c000003e syscall=257 success=no exit=-13 a0=ffffff9c a1=7f8db803f598 a2=80000 a3=0 items=0 ppid=15063 pid=15065 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
    type=AVC msg=audit(1553776770.651:17000): avc:  denied  { open } for  pid=15065 comm="httpd" path="/custom/index.html" dev="vda1" ino=4208311 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file permissive=0
  7. Для устранения проблемы используйте команды semanage и restorecon. Контекст, с которым необходимо работать, — httpd_sys_content_t.

    [root@servera ~]# semanage fcontext -a \
    -t httpd_sys_content_t '/custom(/.*)?'
    [root@servera ~]# restorecon -Rv /custom
    Relabeled /custom from unconfined_u:object_r:default_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0
    Relabeled /custom/index.html from unconfined_u:object_r:default_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0
  8. Снова попробуйте открыть http://servera/index.html. Вы увидите сообщение This is SERVERA.

  9. Выйдите с servera.

    [root@servera ~]# exit
    logout
    [student@servera ~]$ exit
    logout
    Connection to servera closed.
    [student@workstation ~]$ 

Конец

На workstation запустите сценарий lab selinux-issues finish, чтобы закончить упражнение.

[student@workstation ~]$ lab selinux-issues finish

Упражнение завершено.